package com.ex.orage2app;

import android.content.Context;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;


import androidx.recyclerview.widget.RecyclerView;

import java.util.List;

public class MyAdapter extends BaseAdapter {
    private List<String> productCategory;
    private LayoutInflater layoutInflater;
    private int selectPosition=-1;
    public MyAdapter (List<String> productCategory, Context context){
      this.productCategory=productCategory;
      this.layoutInflater=LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return productCategory.size();
    }

    @Override
    public Object getItem(int i) {
        return productCategory.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
       ViewHolder viewHolder=null;
       if(view==null){
           viewHolder=new ViewHolder() ;
           view=layoutInflater.inflate(R.layout.category_list_item,null);
           Log.i("adapts","getview"+view);
           viewHolder.tv=view.findViewById(R.id.categor_titles);
           view.setTag(viewHolder);
       }else {
           viewHolder=(ViewHolder) view.getTag();
       }
       viewHolder.tv.setText(productCategory.get(i));
       if(selectPosition==i){
           viewHolder.tv.setBackgroundColor(Color.YELLOW);

       }else {
           viewHolder.tv.setBackgroundColor(Color.WHITE);
       }
        return view;
    }

    public void setSelectedPosition(int position) {
        this.selectPosition = position;
    }

    class ViewHolder{
        TextView tv;
    }
}
